package com.mission.schedule.fragment;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Transformation;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.lcf.refreshlibrary.PullToRefreshBase;
import com.lcf.refreshlibrary.PullToRefreshScrollView;
import com.mission.schedule.CommonDialog.NoteChildMenuDialog;
import com.mission.schedule.CommonDialog.NoteTypeMenuDialog;
import com.mission.schedule.R;
import com.mission.schedule.activity.MainActivity;
import com.mission.schedule.activity.MyKzoneActivity;
import com.mission.schedule.activity.NewFriendsActivity;
import com.mission.schedule.activity.NoteEditActivity;
import com.mission.schedule.activity.NoteTitleSortActivity;
import com.mission.schedule.activity.NoteTypepxActivity;
import com.mission.schedule.activity.QDFXDetailActivity;
import com.mission.schedule.activity.QDFXDetailListActivity;
import com.mission.schedule.activity.QDFXGLListActivity;
import com.mission.schedule.activity.SelectionFirendActivity;
import com.mission.schedule.adapter.NoteExpandListAdapter;
import com.mission.schedule.applcation.App;
import com.mission.schedule.bean.NoteTypeBean;
import com.mission.schedule.bean.qd606.NoteTitleDetailBean;
import com.mission.schedule.constants.FristFragment;
import com.mission.schedule.constants.ShareFile;
import com.mission.schedule.constants.URLConstants;
import com.mission.schedule.cutimage.Log;
import com.mission.schedule.service.NoteService;
import com.mission.schedule.utils.DateUtil;
import com.mission.schedule.utils.ListViewForScrollView;
import com.mission.schedule.utils.NetUtil;
import com.mission.schedule.utils.ProgressUtil;
import com.mission.schedule.utils.SharedPrefUtil;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.regex.Pattern;

import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.onekeyshare.OnekeyShare;

/**
 * Created by liwei on 2017/2/7.
 */

public class QDListFragment extends BaseFragment implements View.OnClickListener {

    private boolean isShow = false;// 判断是否已经显示
    public static LinearLayout top_ll_left;
    LinearLayout myfriend_ll;
    RelativeLayout addqd_ll_right;
    Context context;
    ImageButton add_btn_image;
    TextView myschedule_title;
    pullRecevier pullRecevier;
    openStateRecevier openStateRecevier;

    ArrayList<NoteTitleDetailBean.TDelListBean> tDelListBeanArrayList = new ArrayList<>();

    SharedPrefUtil sharedPrefUtil;
    String downtime = "2016-01-01";

    String ISNOTETB = "1";//0同步 1不同步

    PullToRefreshScrollView pullToRefreshScrollView;
    NoteExpandListAdapter expandListAdapter;
    ArrayList<NoteTitleDetailBean.TDelListBean> listList = new ArrayList<>();
    ProgressUtil progressUtil = new ProgressUtil();
    ListViewForScrollView listview;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_qdlist, container, false);
    }

    @Override
    protected void lazyLoad() {
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        init();
//        send(7);
    }

    @Override
    public void onHiddenChanged(boolean hidden) {
        super.onHiddenChanged(hidden);
        Log.e("TAG", "onHiddenChanged");
        if (!hidden && !isShow) {// && !isShow
            isShow = true;
            Log.e("TAG", "1");
            send(7);
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (pullRecevier != null) {
            context.unregisterReceiver(pullRecevier);
        }
        if (openStateRecevier != null) {
            context.unregisterReceiver(openStateRecevier);
        }
    }

    @Override
    public void onResume() {
        super.onResume();
    }
    String username = "";

    @TargetApi(Build.VERSION_CODES.M)
    private void init() {

        View view = getView();
        context = getActivity();

        pullRecevier = new pullRecevier();
        IntentFilter filter = new IntentFilter();
        filter.addAction("pullRecevier");
        context.registerReceiver(pullRecevier, filter);

        openStateRecevier = new openStateRecevier();
        IntentFilter openStateRecevierfilter = new IntentFilter();
        openStateRecevierfilter.addAction("openStateRecevier");
        context.registerReceiver(openStateRecevier, filter);

        sharedPrefUtil = new SharedPrefUtil(context, ShareFile.USERFILE);
        userID = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERID, "0");
        username = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERNAME, "");
        downtime = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.UPDATESETTIME, "2016-01-01 00:00:01");
        ISNOTETB = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ISNOTETB, "1");

        top_ll_left = null;
        top_ll_left = view.findViewById(R.id.top_ll_left);
        top_ll_left.setOnClickListener(this);
        myschedule_title = view.findViewById(R.id.myschedule_title);
        addqd_ll_right = view.findViewById(R.id.addqd_ll_right);
        addqd_ll_right.setOnClickListener(this);
        myfriend_ll = view.findViewById(R.id.myfriend_ll);
        myfriend_ll.setOnClickListener(this);
        add_btn_image = view.findViewById(R.id.add_btn_image);
        add_btn_image.setOnClickListener(this);

        pullToRefreshScrollView = view.findViewById(R.id.expand_listview);
        View hv = LayoutInflater.from(context).inflate(R.layout.qd_myzone_header, null);
        View fv = LayoutInflater.from(context).inflate(R.layout.emptry_foolterview, null);
        listview = view.findViewById(R.id.listview);
        if (listview.getHeaderViewsCount() == 0) {
            listview.addHeaderView(hv);
        }
        if (listview.getFooterViewsCount() == 0) {
            listview.addFooterView(fv);
        }

        pullToRefreshScrollView.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() {
            @Override
            public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) {
                if (NetUtil.getConnectState(context) != NetUtil.NetWorkState.NONE) {
                    if (sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ISNEWYOUKE, "0").equals("-1")) {
                        Intent intentnewf = new Intent(context, NoteService.class);
                        intentnewf.setAction("notedData");
                        intentnewf.putExtra("loadType", 2);//2 下拉下载
                        intentnewf.setPackage(context.getPackageName());
                        context.startService(intentnewf);
                    } else {
                        pullToRefreshScrollView.onRefreshComplete();
                    }
                } else {
                    Toast.makeText(context, "请检查您的网络是否正常！", Toast.LENGTH_SHORT).show();
                    pullToRefreshScrollView.onRefreshComplete();
                }
            }

            @Override
            public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) {

            }
        });
        hv.findViewById(R.id.faxian_k).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MyKzoneActivity.class);
                intent.putExtra("userid", userID);
                intent.putExtra("name", username);
                startActivity(intent);
            }
        });

    }

    class dbToAllList extends AsyncTask {

        @Override
        protected Object doInBackground(Object[] objects) {
            send(7);
            return null;
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.addqd_ll_right:
                send(9);
                break;
            case R.id.add_btn_image:// 新建清单
                Intent intent = new Intent(context, NoteEditActivity.class);
                intent.putExtra("remark1", "0");
                startActivityForResult(intent, 600);
                break;
            case R.id.top_ll_left:
                break;
            case R.id.bwl_ll:
                Intent intentbwl = new Intent(context, NoteEditActivity.class);
                intentbwl.putExtra("qdlistenter", false);
                intentbwl.putExtra("titleid", "" + zeroTitleId);
                intentbwl.putExtra("path", "" + zeroPath);
                intentbwl.putExtra("id", id);
                intentbwl.putExtra("title", zeroTitle);
                intentbwl.putExtra("ltype", zeroType + "");
                intentbwl.putExtra("styles", zeroStyles);
                intentbwl.putExtra("copys", zeroCopys);
                startActivityForResult(intentbwl, 600);
                break;
            default:
                break;
        }
    }

    String userID = "";

    String zeroPath = "";
    String zeroTitle = "";
    String zeroTime = "";
    String zeroShare = "";
    String zeroTitleId = "";
    String zeroCopys = "1";
    int zeroStyles = 0;
    int zeroType = 0;
    int id = 0;

    private void send(int index) {
        Message message = new Message();
        message.what = index;
        handler.sendMessage(message);
    }

    private Handler handler = new Handler() {

        @SuppressWarnings("unchecked")
        @Override
        public void handleMessage(final Message msg) {
            super.handleMessage(msg);
            final int g = msg.arg1;
            switch (msg.what) {
                case 0:

                    break;
                case 1://删除清单
//                    xListView.hiddenRight();
//                    qdListAdapter.notifyDataSetChanged();
//                    xListView.invalidate();
//                    send(3);
                    break;
                case 2:
                    Intent intent;
                    if (listList.get(msg.arg1).remark3.equals("2")) {
                        intent = new Intent(context, QDFXDetailActivity.class);
                        intent.putExtra("title", listList.get(msg.arg1).titles);
                        intent.putExtra("titleId", listList.get(msg.arg1).titleId);
                        intent.putExtra("path", listList.get(msg.arg1).imgPath);
                        intent.putExtra("goodNum", "0");
                        intent.putExtra("redNum", "1");
                        intent.putExtra("name", listList.get(msg.arg1).pname);
                        intent.putExtra("time", listList.get(msg.arg1).createTime);
                        intent.putExtra("num", listList.get(msg.arg1).nums + "");
                        intent.putExtra("uid", listList.get(msg.arg1).puid + "");
                        intent.putExtra("stylee", listList.get(msg.arg1).styles);
                        intent.putExtra("type", 5);
                    } else if (listList.get(msg.arg1).remark3.equals("1")) {
                        intent = new Intent(context, QDFXDetailActivity.class);
                        intent.putExtra("title", listList.get(msg.arg1).titles);
                        intent.putExtra("titleId", listList.get(msg.arg1).titleId);
                        intent.putExtra("path", listList.get(msg.arg1).imgPath);
                        intent.putExtra("goodNum", "0");
                        intent.putExtra("redNum", "1");
                        intent.putExtra("name", listList.get(msg.arg1).pname);
                        intent.putExtra("time", listList.get(msg.arg1).createTime);
                        intent.putExtra("num", listList.get(msg.arg1).nums + "");
                        intent.putExtra("uid", listList.get(msg.arg1).puid + "");
                        intent.putExtra("stylee", listList.get(msg.arg1).styles);
                        intent.putExtra("type", 0);
                    } else {
                        intent = new Intent(context, NoteEditActivity.class);
                        intent.putExtra("qdlistenter", false);
                        intent.putExtra("titleid", "" + listList.get(msg.arg1).titleId);
                        intent.putExtra("path", "" + listList.get(msg.arg1).imgPath);
                        intent.putExtra("id", listList.get(msg.arg1).id);
                        intent.putExtra("title", listList.get(msg.arg1).titles);
                        intent.putExtra("ltype", listList.get(msg.arg1).ltype + "");
                        intent.putExtra("styles", listList.get(msg.arg1).styles);
                        intent.putExtra("copys", listList.get(msg.arg1).copys);
                        intent.putExtra("remark", listList.get(msg.arg1).remark);
                        intent.putExtra("remark1", listList.get(msg.arg1).remark1);
                        intent.putExtra("openState", listList.get(msg.arg1).openState);
                        intent.putExtra("other1", listList.get(msg.arg1).other1);
                        intent.putExtra("remark5", listList.get(g).remark5 == null ? "0" :listList.get(g).remark5);
                        intent.putExtra("remark6", listList.get(g).remark6 == null ? "0" :listList.get(g).remark6);
                    }
                    startActivityForResult(intent, 600);
                    break;
                case 5:
                    loaddata();
                    send(3);
                    break;
                case 3:
                    tDelListBeanArrayList = App.getDBcApplication().getFiledNoteTitlesData(userID, "0");
                    if (tDelListBeanArrayList.size() > 0) {
                        myschedule_title.setText("我的清单(" + tDelListBeanArrayList.size() + ")");
                    } else {
                        myschedule_title.setText("我的清单");
                    }
                    break;
                case 4:
                    new dbToAllList().execute();
                    break;
                case 6:
                    final String titleid = listList.get(g).titleId;
                    final String titles = listList.get(g).titles;
                    final String remark5 = listList.get(g).remark5 == null ? "0" :listList.get(g).remark5;
                    final String remark6 = listList.get(g).remark6 == null ? "0" :listList.get(g).remark6;
                    NoteChildMenuDialog noteChildMenuDialog = new NoteChildMenuDialog(context, R.style.dialog_translucent,
                            getActivity().getWindowManager(), listList.get(g));
                    noteChildMenuDialog.show();
                    noteChildMenuDialog.setCallBack(new NoteChildMenuDialog.CallBack() {
                        @Override
                        public void updateNoteChildType(int styleid) {
                            send(7);
                        }

                        @Override
                        public void notezhuanfa() {
                            Intent intent = new Intent(getActivity(), SelectionFirendActivity.class);
                            intent.putExtra("titleid", titleid);
                            intent.putExtra("titles", titles);
                            intent.putExtra("remark5", remark5);
                            intent.putExtra("remark6", remark6);
                            intent.putExtra("schRemark1", "");
                            intent.putExtra("updateState", "");
                            intent.putExtra("schID", "");
                            intent.putExtra("schSourceType", "0");
                            startActivity(intent);
                        }

                        @Override
                        public void weixin() {
                            showShare(titles, App.getDBcApplication().getNoteTitleDetailContent(userID, titleid), titleid, 0);
                        }

                        @Override
                        public void copytitle() {
                            App.getDBcApplication().copyNoteTitleData(userID, titleid);
                            send(7);
                        }

                        @Override
                        public void delete() {
                            expandListAdapter.deletelist(g);
                            MainActivity.instance.updateNoteTitleNoReadNums();
                        }

                        @Override
                        public void top() {
                            App.getDBcApplication().updateNoteTitleLocalTimes(titleid, DateUtil.formatDateTimeSs(new Date()));
                            expandListAdapter.topNoteTitle(g);
                        }

                        @Override
                        public void common(int openState, boolean success) {
                            if (!success) {
                                App.getDBcApplication().updateNoteTitleOpenState(userID, listList.get(g).titleId, openState);
                            }
                            expandListAdapter.updateOpenstate(g, openState);
                        }

                        @Override
                        public void copy_myzone() {
                        }

                        @Override
                        public void updateColor(String color_position_f, String color_position) {
                            expandListAdapter.updateOpenstate(g, color_position_f, color_position);
                        }
                    });
                    break;
                case 7:
                    loaddata();
                    setadapter();
                    send(3);
                    break;
                case 9:
                    ClipboardManager clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
                    if (clipboardManager.getText() == null || clipboardManager.getText().toString().isEmpty()) {
                        alertClipIsEmptry();
                    } else {
                        copyAll(clipboardManager.getText().toString());
                    }
                    break;

            }
        }
    };


    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 600) {
            ISNOTETB = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.ISNOTETB, "1");
            if (ISNOTETB.equals("0")) {
                new dbToAllList().execute();
            } else {
                sharedPrefUtil.putString(context, ShareFile.USERFILE, ShareFile.ISNOTETB, "1");
            }
        }
    }

    private void setadapter() {
        expandListAdapter = new NoteExpandListAdapter(context, handler, listList);
        listview.setAdapter(expandListAdapter);
        expandListAdapter.notifyDataSetChanged();
    }

    public void loaddata() {
        Log.e("TAG", "2");
        userID = sharedPrefUtil.getString(context, ShareFile.USERFILE, ShareFile.USERID, "0");
        listList = App.getDBcApplication().getFiledNoteTitlesTypeData(userID, "0", "");//isMyNote ? "0" : "1,bean.localId +

        Collections.sort(listList, new Comparator<NoteTitleDetailBean.TDelListBean>() {
            @Override
            public int compare(NoteTitleDetailBean.TDelListBean lhs, NoteTitleDetailBean.TDelListBean rhs) {
                return rhs.localTimes.compareTo(lhs.localTimes);
            }
        });
    }

    //分享其他
    private void showShare(String Title, String contents, String titleid, int nums) {
        ShareSDK.initSDK(context);
        OnekeyShare oks = new OnekeyShare();
        // 关闭sso授权
        oks.disableSSOWhenAuthorize();
        oks.setTitle(Title);
        oks.setText(contents);

        String url = "http://www.keytimeapp.com/qingdan/qdlist-user.html?uId=" + userID + "&titleId=" + titleid + "&title=" + Title + "&name=" + sharedPrefUtil.getString(context, ShareFile.USERFILE,
                ShareFile.USERNAME, "") + "&number=" + nums + "&from=singlemessage&isappinstalled=1&type=1";
        oks.setUrl(url);
        oks.setImageUrl(URLConstants.图片 + sharedPrefUtil.getString(context,
                ShareFile.USERFILE, ShareFile.USERPHOTOPATH, "") + "&imageType=2&imageSizeType=3");
        // 启动分享GUI
        oks.show(context);
    }

    private void copyAll(String content) {
        if (content.length() > 1) {
            if (content.substring(0, 2).equals("**")) {
                String[] notecontent = content.substring(1, content.length()).split("\\*");
                if (notecontent.length >= 2) {
                    String[] conde = notecontent[notecontent.length - 1].split("\n");
                    String title = notecontent[0];
                    for (int i = 0; i < notecontent.length - 1; i++) {
                        if (!notecontent[i].isEmpty()) {
                            title = notecontent[i];
                        }
                    }
                    NoteTitleDetailBean.TDelListBean bean = titlebean(title, false);
                    int i = 0;
                    for (String item : conde) {
                        if (!item.isEmpty()) {
                            debean(bean.titleId, i, item, bean.titles, false);
                            i++;
                        } else {
                            continue;
                        }
                    }
                    expandListAdapter.copyOneNoteTitle(bean.titleId, userID);
                } else if (notecontent.length == 1) {
                    String[] conde = notecontent[0].split("\n");
                    NoteTitleDetailBean.TDelListBean bean = titlebean("", false);
                    if (conde != null) {
                        int i = 0;
                        for (String item : conde) {
                            if (!item.isEmpty()) {
                                debean(bean.titleId, i, item, bean.titles, false);
                                i++;
                            } else {
                                continue;
                            }
                        }
                    }
                    expandListAdapter.copyOneNoteTitle(bean.titleId, userID);
                }
            } else {
                String[] conde = content.split("\n");
                NoteTitleDetailBean.TDelListBean bean = titlebean("", true);
                if (conde != null) {
                    int i = 0;
                    for (String item : conde) {
                        if (!item.isEmpty()) {
                            debean(bean.titleId, i, item, bean.titles, true);
                            i++;
                        } else {
                            continue;
                        }
                    }
                }
                expandListAdapter.copyOneNoteTitle(bean.titleId, userID);
            }
            send(7);
        }
    }

    public static boolean isInteger(String str) {
        Pattern pattern = Pattern.compile("^[-\\+]?[\\d]*$");
        return pattern.matcher(str).matches();
    }

    private NoteTitleDetailBean.TDelListBean titlebean(String titles, boolean isCopyType) {


        NoteTitleDetailBean.TDelListBean bean = new NoteTitleDetailBean.TDelListBean();
        bean.titleId = DateUtil.nowTime1();
        bean.uid = Integer.valueOf(userID);
        bean.id = App.getDBcApplication().getTiMinId() - 1;
        bean.styles = isCopyType ? 0 : 3;
        bean.changeTime = DateUtil.nowTime();
        bean.createTime = DateUtil.nowTime();
        bean.localTimes = DateUtil.nowTime();
        bean.ltype = 0;
        bean.orderId = 0;
        bean.copys = "0";
        bean.filed = "0";
        bean.titles = titles;
        bean.imgPath = "";
        bean.imgUrl = "";
        bean.nums = "";
        bean.shareUrl = "";
        bean.remark = titles.isEmpty() ? "1" : "0";
        bean.remark1 = "备忘录";
        bean.remark2 = "";
        bean.remark3 = "";
        bean.pname = "";
        bean.puid = 0;
        bean.states = 0;
        bean.sends = 0;
        bean.openState = 0;

        App.getDBcApplication().saveNoteTitleData(bean);
        App.getDBcApplication().updateNoteTitleState(bean.titleId, userID, 1, false);

        return bean;
    }

    /**
     * @param titleId
     * @param orderid
     * @param content
     * @param titles
     * @param isCopyType true 不是全部复制
     */
    private void debean(String titleId, int orderid, String content, String titles, boolean isCopyType) {
        NoteTitleDetailBean.ListBean beand = new NoteTitleDetailBean.ListBean();
        beand.titleId = titleId;
        beand.uid = Integer.valueOf(userID);
        beand.id = App.getDBcApplication().getMinId() - 1;
        beand.style = isCopyType ? 0 : 3;
        beand.changetime = DateUtil.nowTime();
        beand.createTime = DateUtil.nowTime();
        beand.lType = 0;
        beand.orderId = orderid;
        beand.endstate = 0;
        beand.remark = "";
        beand.contents = content;
        beand.titles = titles;
        beand.imgPath = "";
        beand.imgUrl = "";
        beand.cpath = "";
        beand.curl = "";
        beand.nums = "";
        beand.shareUrl = "";
        beand.remark1 = "";
        beand.remark2 = "";
        beand.remark3 = "";
        beand.remark4 = "";

        App.getDBcApplication().saveNoteDetailData(beand);
        App.getDBcApplication().updateNoteTitleDetailState(titleId, beand.id, userID, 1, true);

    }

    private class pullRecevier extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            send(7);
            pullToRefreshScrollView.onRefreshComplete();
        }
    }

    public void onEventMainThread(FristFragment event) {

        String msg = event.getMsg();
        if ("1".equals(msg) && isShow) {
//            send(7);
        }
    }

    private class openStateRecevier extends BroadcastReceiver {

        @Override
        public void onReceive(Context context, Intent intent) {
            progressUtil.dismiss();
        }
    }

    private void alertClipIsEmptry() {
        final AlertDialog builder = new AlertDialog.Builder(context).create();
        builder.show();
        Window window = builder.getWindow();
        android.view.WindowManager.LayoutParams params = window.getAttributes();// 获取LayoutParams
        params.alpha = 0.92f;
        params.gravity = Gravity.CENTER;
        window.setAttributes(params);// 设置生效
        window.setGravity(Gravity.CENTER);
        window.setContentView(R.layout.dialog_alert_ok);
        TextView delete_ok = (TextView) window.findViewById(R.id.delete_ok);
        TextView delete_tv = (TextView) window.findViewById(R.id.delete_tv);
        delete_tv.setText("粘贴内容不能为空！");
        delete_ok.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                builder.cancel();
            }
        });

    }

    private void noteTypeBean(int localId, String name, int orderId, int styleid) {
        NoteTypeBean.ListBean bean = new NoteTypeBean.ListBean();
        bean.id = 0;
        bean.uid = Integer.valueOf(userID);
        bean.content = name;
        bean.changeTime = DateUtil.formatDateTimeSs(new Date());
        bean.orderId = orderId;
        bean.styleId = styleid;
        bean.localId = localId;
        bean.remark = "";
        bean.remark1 = "";

        App.getDBcApplication().saveNoteTypeData(bean);
    }


    private void deletePattern(final View view, final int groupposition, final int childposition) {

        Animation.AnimationListener al = new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {

            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        };
        collapse(view, al);

    }

    private void collapse(final View view, Animation.AnimationListener al) {
        final int originHeight = view.getMeasuredHeight();

        Animation animation = new Animation() {
            @Override
            protected void applyTransformation(float interpolatedTime, Transformation t) {
                if (interpolatedTime == 1.0f) {
                    view.setVisibility(View.GONE);
                } else {
                    view.getLayoutParams().height = originHeight - (int) (originHeight * interpolatedTime);
                    view.requestLayout();
                }
            }

            @Override
            public boolean willChangeBounds() {
                return true;
            }
        };
        if (al != null) {
            animation.setAnimationListener(al);
        }
        animation.setDuration(300);
        view.startAnimation(animation);
    }
}
